﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.IO;
using System.Windows.Forms;

namespace weiqijiance.转速仪
{
     public class zsybass
     {
         public int m_iGasturn = 0;//转速
         public SerialPort commex = new SerialPort();//废气仪串口
         public virtual bool openCOM(string sSet1)
         {
             string[] szbzlCOM = new string[5];
             if (sSet1.Length > 0)
                 szbzlCOM = sSet1.Split(':');
             //打开串口
             commex.PortName = szbzlCOM[0];
             commex.BaudRate = Convert.ToInt32(szbzlCOM[1]);

             commex.NewLine = "/r/n";
             commex.RtsEnable = true;//根据实际情况吧。 
             commex.ReadTimeout = 300;//读取数据延时，避免读取不全数据

             if (szbzlCOM[3] == "0")
                 commex.Parity = Parity.None;
             else
                 commex.Parity = Parity.Even;
             // ////添加事件注册  
             //  comm.DataReceived += comm_Data;
             try
             {
                 commex.Open();
             }
             catch (Exception)
             {
                //lzj20200706 MessageBox.Show(string.Format("{0}\n请检查电脑的串口故障", ex.Message));
                 return false;
             }
             return true;
         }

         /// <summary>
         /// 发送开始测量
         /// </summary>
         /// <returns></returns>
         public virtual bool SendDeviceCmd()
         {
             return true;
         }
    }
}
